#include<bits/stdc++.h>
using namespace std;
typedef tuple<int,int,int> tpi;
class pq{
  private:
    priority_queue<tpi> q1,q2;
  public:
    void add(tpi x){q1.emplace(x);}
    void del(tpi x){q2.emplace(x);}
    tpi top(){
      while(!q1.empty()&&!q2.empty()&&q1.top()==q2.top())
        q1.pop(),q2.pop();
      return q1.top();
    }
};
int main(){
  freopen("sub.in","r",stdin);
  freopen("sub.out","w",stdout);
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  int n,k,c=0; cin>>n>>k;
  vector<int> a(n);
  for(auto &i:a)cin>>i;
  priority_queue<tpi> q;
  vector<tpi> info(n);
  for(int i=0;i<n;i++)
    q.emplace(info[i]=make_tuple(max(a[(i+n-1)%n]+a[i],a[i]+a[(i+1)%n]),a[i],i));
  vector<pair<int,int> > ls(n);
  for(int i=0;i<n;i++)
    ls[i]=make_pair((i+n-1)%n,(i+1)%n);
  auto mdf=[&](int x){
    int a,b; tie(a,b)=ls[x];
    ls[b].first=a,ls[a].second=b;
    ls[x]=make_pair(-1,-1);
    return make_pair(a,b);
  };
  vector<bool> dl(n);
  for(int i=0;i<n-k;i++){
    int u=get<2>(q.top());
    while(q.top()!=info[u]||dl[u])
      q.pop(),u=get<2>(q.top());
    dl[u]=true,q.pop();
    int x,y; tie(x,y)=mdf(u);
    {
      int f,g; tie(f,g)=ls[x];
      info[x]=make_tuple(max(a[f]+a[x],a[x]+a[g]),a[x],x);
    }
    {
      int f,g; tie(f,g)=ls[y];
      info[y]=make_tuple(max(a[f]+a[y],a[y]+a[g]),a[y],y);
    }
    q.emplace(info[x]),q.emplace(info[y]);
  }
  vector<int> v;
  for(int i=0;i<n;i++)
    if(~ls[i].first)v.emplace_back(i);
  for(int i=0;i<v.size();i++)
    c=max(c,a[v[i]]+a[v[(i+1)%v.size()]]);
  cout<<c<<endl;
  return 0;
}